<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
	<link rel="stylesheet" href="layui/css/layui.css">
	<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<style type="text/css">
		body{
			padding: 20px;
		}
	</style>
	<body>
		<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">设备名称</label>
    <div class="layui-input-block" style="width: 200px;">
      <input type="text" name="deviceName" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">单位</label>
    <div class="layui-input-block" style="width: 200px;">
      <select name="unitId" lay-verify="required" lay-filter="test1">
		  <option></option>
        <option value="6a2ba203-b19f-4eca-8073-663b0a4903b5">万象城</option>
        <option value="cade580caca84f47ad07f6113c1cebff">宁夏展厅</option>
        
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">单选框</label>
    <div class="layui-input-block">
      <input type="radio" name="status" value="报警" title="报警">
	  <input type="radio" name="status" value="异常" title="异常">
      <input type="radio" name="status" value="故障" title="故障" checked>
    </div>
  </div>
  
    <div class="layui-form-item">
    <label class="layui-form-label">单选框</label>
    <div class="layui-input-block">
  	  <input type="radio" name="msg" value="fireFan" title="水泵风机">
      <input type="radio" name="msg" value="warningVoice" title="语音" checked>
    </div>
  </div>
  
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
 
<script>
//Demo
layui.use('form', function(){
	var unitName = '';
  var form = layui.form;
	 form.on('select(test1)', function(data){
		 console.log(data)
		  console.log(data.elem); //得到select原始DOM对象
		  console.log(data.value); //得到被选中的值
		  console.log(data.othis); //得到美化后的DOM对象
		  console.log(data.elem[data.elem.selectedIndex].text); //得到select选中项的值
			unitName = data.elem[data.elem.selectedIndex].text;
	});   
  
  //监听提交
  form.on('submit(formDemo)', function(data){
	  console.log(data)
	   var url = "http://api.zfjituan.com//cheat/index?"+"deviceName="+data.field.deviceName+
					"&status="+data.field.status+
					"&unitId="+data.field.unitId+
					"&unitName="+unitName+
					"&msg="+data.field.msg;
					var data = null;

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
	layer.msg(this.responseText);
  }
});

xhr.open("GET", url);

xhr.send(data);
    
    return false;
  });
});
</script>
	</body>
</html>
